package com.example.movie.mate.controller;

import com.example.movie.mate.pojo.param.MovieAddNewParam;
import com.example.movie.mate.pojo.vo.MovieVO;
import com.example.movie.mate.service.IMovieService;
import com.example.movie.mate.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 电影控制器
 */
@Tag(name = "2. 电影管理模块")
@RestController
@RequestMapping("/api/movie")
public class MovieController {

    @Autowired
    private IMovieService movieService;

    @ApiOperationSupport(order = 100)
    @Operation(summary = "[管理] 新增电影")
    @PostMapping("/manage/add-new")
    public JsonResult<Void> addNew(@ParameterObject @Valid MovieAddNewParam param) {
        movieService.addNew(param);
        return JsonResult.ok();
    }

    @ApiOperationSupport(order = 410)
    @Operation(summary = "[游客] 根据ID查询电影信息")
    @Parameter(name = "id", description = "电影id", required = true, example = "1")
    @GetMapping("/public/{id}")
    public JsonResult<MovieVO> selectById(@PathVariable Long id) {
        MovieVO data = movieService.selectById(id);
        return JsonResult.ok(data);
    }

    @ApiOperationSupport(order = 420)
    @Operation(summary = "[游客] 查询正在上映的电影列表")
    @GetMapping("/public/on-schedule")
    public JsonResult<List<MovieVO>> selectAllOnSchedule() {
        List<MovieVO> list = movieService.selectAllOnSchedule();
        return JsonResult.ok(list);
    }

    @ApiOperationSupport(order = 421)
    @Operation(summary = "[游客] 查询未上映的电影列表")
    @GetMapping("/public/not-on-schedule")
    public JsonResult<List<MovieVO>> selectAllNotOnSchedule() {
        List<MovieVO> list = movieService.selectAllNotOnSchedule();
        return JsonResult.ok(list);
    }

}